import type { VxeGridProps } from '@vben/plugins/vxe-table';

import type { VbenFormProps } from '#/adapter/form';
import type { DefDictModel } from '#/api/devOperation/system/model/defDictModel';

import { $t } from '@vben/locales';

const formatterYesNo = ({
  cellValue,
}: {
  cellValue: DefDictModel.DefDictResultVO;
}) => {
  return cellValue ? $t('common.enable') : $t('common.disable');
};

// 表格参数定义
export const gridSchemas: VxeGridProps<DefDictModel.DefDictResultVO> = {
  toolbarConfig: {
    perfect: true,
    buttons: [
      { code: 'myInsert', name: $t('common.title.add') },
      {
        code: 'batchDelete',
        name: $t('common.title.delete'),
        status: 'danger',
      },
    ],
  },
  editConfig: {
    trigger: 'click',
    mode: 'row',
    showStatus: true,
    autoClear: true,
  },
  sortConfig: { defaultSort: { field: 'sortValue', order: 'desc' } },
  columns: [
    { type: 'checkbox', width: 50 },
    { title: $t('common.seq'), type: 'seq', width: 50 },
    {
      field: 'key',
      title: $t('devOperation.system.defDictItem.key'),
      editRender: {
        name: 'Input',
        attrs: { placeholder: $t('common.inputText') },
      },
    },
    {
      field: 'name',
      title: $t('devOperation.system.defDictItem.name'),
      editRender: {
        name: 'Input',
        attrs: { placeholder: $t('common.inputText') },
      },
    },
    {
      field: 'state',
      width: 100,
      title: $t('devOperation.system.defDict.state'),
      editRender: {
        name: 'Switch',
        attrs: { placeholder: $t('common.inputText') },
      },
      formatter: formatterYesNo,
    },
    {
      field: 'sortValue',
      width: 120,
      sortable: true,
      title: $t('devOperation.developer.defGenTableColumn.sortValue'),
      editRender: {
        name: 'InputNumber',
        attrs: { placeholder: $t('common.inputText') },
      },
    },
    {
      field: 'createdTime',
      formatter: 'formatDateTime',
      sortable: true,
      width: 180,
      title: $t('common.createdTime'),
    },
    {
      field: 'action',
      fixed: 'right',
      title: '操作',
      slots: { default: 'ACTION' },
      width: 150,
    },
  ],
};
// 搜索表单参数定义
export const searchFormSchemas: VbenFormProps = {
  schema: [
    {
      component: 'Input',
      fieldName: 'key',
      label: $t('devOperation.system.defDictItem.key'),
      componentProps: {
        placeholder: $t('common.inputText'),
        allowClear: true,
      },
    },
    {
      component: 'Input',
      fieldName: 'name',
      label: $t('devOperation.system.defDictItem.name'),
      componentProps: {
        placeholder: $t('common.inputText'),
        allowClear: true,
      },
    },
  ],
};
